<!DOCTYPE html>
<html>
<head>
    <meta content="text/html" charset="UTF-8">
    <title>微信管理平台</title>
    <link rel="stylesheet" type="text/css" href="css/themes/default/easyui.css">
    <link rel="stylesheet" href="css/themes/icon.css"/>
    <link rel="stylesheet" href="css/themes/color.css"/>
    <link rel="stylesheet" type="text/css" href="css/mycss.css"/>
    <link rel="stylesheet" type="text/css" href="css/themes/portal.css"/>
    <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="js/jquery.easyui.min.js"></script>
</head>
<body>
<div class="easyui-layout" fit="true">
    <div data-options="region:'west',split:true,border:false" style="width: 700px">
        <table id="weixin_usergroup_datagird"></table>
    </div>
    <div data-options="region:'center',split:true,border:true,title:'权限分配',tools:[
            {
                iconCls:'icon-save',
                handler:function(){
                    var nodes = $weixin_grouprole_tree.tree('getChecked', ['checked','indeterminate']);
                    if(nodes.length>0){
                    	var groupid=$weixin_grouprole_tree.tree('options').queryParams.groupid;
                    	var ids=[];
                    	$.each(nodes,function(i,n){
                    		ids.push(n.id);
                    	});
                    	$.post('usergroup/api?method=uprole',{groupid:groupid,ids:ids.join(',')},undefined,'json');
                    }
                    console.log(nodes);
                }
            },{
                iconCls:'icon-edit',
                handler:function(){alert('edit')}
            }]">
        <ul id="weixin_grouprole_tree"></ul>
    </div>
</div>

<div style="display: none">
    <div id="weixin_role_dialog">Dialog Content.</div>
</div>
<script type="text/javascript">
    var $=$||{};
    var $weixin_usergroup_datagird=$('#weixin_usergroup_datagird');
    var rolebtn=$("<a href='javascript:showrole()'>你好</a>").linkbutton({iconCls:'icon-search',plain:true}).prop('outerHTML');
    var $weixin_role_dialog=$('#weixin_role_dialog');
    var $weixin_grouprole_tree=$('#weixin_grouprole_tree');
    $weixin_usergroup_datagird.datagrid({
        url:'usergroup/list.json',
        saveUrl:'usergroup/api?method=add',
        editUrl:'usergroup/api?method=update',
        delUrl:'usergroup/api?method=del',
        columns: [
            [
                {field:'ck',checkbox:true},
                {field: 'id', title: 'Id'},
                {field: 'groupname', title: '组名',width:80,editor:{type:'textbox',options:{required:true}}},
                {field: 'groupdes', title: '组描述', width: 180,editor:{type:'textbox',options:{required:true}}},
                {field: 'btn', title: '操作', formatter: function () {
                 return rolebtn;
                 }}
            ]
        ],
        onBeforeEdit:function(rowIndex){
            var items=$weixin_usergroup_datagird.datagrid('options').edititem;
            items.push(rowIndex);
        },
        onDblClickRow:function(rowIndex){
            $weixin_usergroup_datagird.datagrid('beginEdit',rowIndex);
        },
        toolbar:[
            {
                iconCls:'icon-add',
                text:'添加',
                handler:function(){
                    $weixin_usergroup_datagird.datagrid('addRow',{
                        "groupname":"管理组",
                    });
                }
            },
            {
            	iconCls:'icon-save',
            	text:'接受更改',
            	handler:function(){
            		$weixin_usergroup_datagird.datagrid('RecChange');
            	}
            },
            {
                iconCls:'icon-save',
                text:'保存',
                handler:function(){
                    $weixin_usergroup_datagird.datagrid('SaveData');
                }
            },
            {
                iconCls:'icon-cancel',
                text:'取消更改',
                handler:function(){
                    $weixin_usergroup_datagird.datagrid('CancelEdit');
                }
            },
            {
                iconCls:'icon-remove',
                text:'删除',
                handler:function(){
                	$weixin_usergroup_datagird.datagrid('DelRows');

                }
            }
        ]
    });
    $weixin_grouprole_tree.tree({
        url:'menu/allmenus?type=group',
        fit:true,
        method:'get',
        border:true,
        checkbox:true,
        onClick:function(node){
            $weixin_grouprole_tree.tree('toggle',node.target);
        }
    });
    $weixin_role_dialog.dialog({
        title: 'My Dialog',
        width: 400,
        height: 200,
        closed: true,
        cache: false,
        modal: true
    });

    function showrole(){
        var row=$weixin_usergroup_datagird.datagrid('getSelected');
        console.log(row);
        $weixin_grouprole_tree.tree('options').queryParams.groupid=row.id;
        $weixin_grouprole_tree.tree('reload');
    }

</script>
</body>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jquery.portal.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="js/init.js"></script>
<script type="text/javascript" src="js/jquery.edatagrid.js"></script>
</html>